package com.controller;

import com.pojo.Msg;
import com.pojo.Order;
import com.pojo.Payment;
import com.service.OrderService;
import com.service.PaymentService;
import com.shiro.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;


//@RequiresPermissions(value={"cashierOrder:*"})
@Controller
@ResponseBody
public class PaymentController extends BaseController {
    @Autowired
    PaymentService paymentService;

    @Autowired
    OrderService orderService;


    @RequestMapping(value="/pay", method= RequestMethod.POST)
    @ResponseBody
    public Msg pay (@RequestBody Payment payment) {
        //需要防止重复提交
        BigDecimal balance = paymentService.pay(payment);
        if(balance == null){
            return Msg.fail().add("message","金额不足，请重新输入");
        }else{
            //更新订单--> 时间，状态  的信息, 更新操作状态
            orderService.finishOrderByOid(payment.getoId());
            Msg msg = Msg.success().add("balance", balance);
            msg.add("message", "支付成功");
            return msg;
        }
    }
}
